export default function (fn, delay = 500) {
	let timer = null
	const _debounce = function (...args) {
		return new Promise((resolve, reject) => {
			if (timer) clearTimeout(timer)
			timer = setTimeout(() => {
				const result = fn.apply(this, args)
				resolve(result)
			}, delay)
		})
	}
	return _debounce
}
